home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / eTLiteral.subproj / eTLiteralUI.m < prev    next >
Encoding:
Text File  |  1994-10-24  |  3.9 KB  |  150 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    eTLiteralUI.m
  3. //    SUMMARY:    Implementation of an inspector for eTLiteral
  4. //    SUPERCLASS:    eTLiteralUI:eTImageUI:Object
  5. //    INTERFACE:    eTLiteralUI.nib
  6. //    PROTOCOLS:    <Inspectable>
  7. //    AUTHOR:        Rohit Khare and Tom Zavisca
  8. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  9. ///////////////////////////////////////////////////////////////////////////////
  10. //  IMPLEMENTATION COMMENTS
  11. //        See the overrides for the <Inspectable> API.
  12. ///////////////////////////////////////////////////////////////////////////////
  13. //    HISTORY
  14. //    07/24/94:    Created. First actual implementation.
  15. ///////////////////////////////////////////////////////////////////////////////
  16.  
  17. #import "eTLiteralUI.h"
  18.  
  19. @implementation eTLiteralUI
  20. //     id         literalPanel;
  21. //     id        literalView;
  22. //     id        etLiteral;
  23. //     id        repText;
  24. //     int        currentFmt;
  25. //     BOOL    textDirty;
  26.  
  27. +new
  28. {
  29.     static eTLiteralUI *ui = nil;
  30.     
  31.     if (!ui) {
  32.         ui = [[eTLiteralUI alloc] init];
  33.     }
  34.     return ui;
  35. }
  36. - init
  37. {
  38.     char        buf[MAXPATHLEN];
  39.     NXBundle   *bundle;
  40.  
  41.     [super init];
  42.     bundle = [NXBundle bundleForClass:[eTLiteralUI class]];
  43.     if ( [bundle getPath:buf forResource:"eTLiteralUI" ofType:"nib"] ) {
  44.         [NXApp loadNibFile:buf owner:self withNames:NO];
  45.     } else {
  46.         NXLogError("NIB not found: eTLiteralUI");
  47.     }
  48.     literalView = [literalPanel contentView];
  49.     [repText setDelegate:self];
  50.     textDirty=NO;
  51.     currentFmt=HTMD_FMT; // don't worry, activateI.. should be callled :)
  52.     return self;
  53. }
  54. - free {return self;}
  55.  
  56. ////////////////// Inspectable API
  57. #define     HTML_REP     NXUniqueString("HTML Representation")
  58. #define        TeXD_REP     NXUniqueString("LaTeX Representation")
  59. #define        C_REP         NXUniqueString("C Code Representation")
  60. #define        ASCII_REP     NXUniqueString("ASCII Representation")
  61.  
  62. - (const NXAtom *) types
  63. {
  64.     static NXAtom *types = NULL;
  65.     
  66.     if (!types) {
  67.         int i;
  68.         const NXAtom *superTypes = [super types];
  69.         
  70.         for(i=0;superTypes[i];i++);
  71.         i++; // make room for terminating NULL
  72.         types = malloc(i+5 * sizeof(NXAtom));
  73.         types[0] = HTML_REP;
  74.         types[1] = TeXD_REP;
  75.         types[2] = C_REP;
  76.         types[3] = ASCII_REP;
  77.         for(i=0;superTypes[i];i++) types[i+4] = superTypes[i];
  78.         types[i+4] = NULL;
  79.     }
  80.     return types;
  81. }
  82. - resignInspector: (View *) oldInspector ofType: (const char *) type
  83. {
  84.     if (oldInspector == literalView) {
  85.         // we have to swap OUT the old....
  86.         [self resetRep:self];
  87.     } else 
  88.         [super resignInspector:oldInspector ofType:type];
  89.     return self;
  90. }
  91. - activateInspector: (View *) newInspector ofType: (const char *) aType
  92. {
  93.     NXAtom type;
  94.     type = NXUniqueString(aType);
  95.     if (newInspector == literalView) {
  96.         //and ring in the NEW...
  97.         if(type==HTML_REP) [self changeFormatTo:HTMD_FMT];
  98.         else if(type==TeXD_REP) [self changeFormatTo:TeXD_FMT]; 
  99.         else if(type==C_REP) [self changeFormatTo:C_FMT];
  100.         else if(type==ASCII_REP) [self changeFormatTo:ASCII_FMT];
  101.         else    
  102.         NXLogError("Massive Inspector Failure: asked eTLiteralUI to activate %s", type);
  103.         }
  104.         else [super activateInspector:newInspector ofType:type];
  105.     return self;
  106. }
  107. - inspectorForType:(const char *) aType
  108. {
  109.     NXAtom type;
  110.     type = NXUniqueString(aType);
  111.     if((type==HTML_REP) || (type==TeXD_REP) || (type==C_REP) || (type== ASCII_REP))    return literalView;
  112.     else    return [super inspectorForType:type];
  113. }
  114. - (const char *)inspectorTitle {return NXUniqueString("Literal Element");}
  115. ////////////////////////
  116.  
  117. - setAnnotation:newLiteral
  118.     {[self resetRep:self];
  119.      etLiteral=newLiteral;
  120.      return [super setAnnotation:newLiteral];}
  121. -resetRep: sender
  122. {
  123.     if(textDirty) {
  124.         [etLiteral     setRep:currentFmt 
  125.                     fromStream:[repText stream] 
  126.                     length:[repText textLength]];
  127.         textDirty=NO;
  128.     }
  129.     return self;
  130. }
  131. -changeFormatTo:(int) newFormat
  132. {
  133.     const char *buf;
  134.  
  135.     currentFmt = newFormat;
  136.     if (buf = [etLiteral theRepForFormat:currentFmt]) {
  137.         [repText setText:buf];
  138.         textDirty = NO;
  139.     } else {
  140.         [repText setText:""];
  141.     }
  142.     return self;
  143. }
  144. -textDidChange: sender
  145. {
  146.     textDirty=YES;
  147.     return self;
  148. }
  149. @end
  150.